using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using WebapiTemplate.Application.Common;
using WebapiTemplate.Infrastructure.Persistence;


namespace WebapiTemplate.Infrastructure
{
    public static class DependencyInjection
    {
        public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
        {
            // //注入数据库依赖
            var constr = configuration.GetConnectionString("SqlServer");//从appsettings.json中获取SqlServer
            
            services.AddDbContext<WebapiDbcontext>(options=>{
                options.UseSqlServer(constr);
            });

            //注入接口和实现类依赖
            services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
            
            return services;
        }
    }    
}   